package com.homework.ch08;

import java.lang.reflect.Method;

/**
 * @author yang
 * @date 2024-03-27
 */
public class BeanTest {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BeanTest(String name) {
        this.name = name;
    }

    public BeanTest() {
    }

    public static void main(String[] args) throws Exception {
        Class<BeanUtil> beanUtilClass = BeanUtil.class;
        Method method = beanUtilClass.getMethod("setProperty", Object.class, String.class, Object.class);
        Class<BeanTest> beanTestClass = BeanTest.class;
        BeanTest beanTest = beanTestClass.getConstructor().newInstance();
        method.invoke(beanUtilClass, beanTest, "name", "张三");

        Object name = BeanUtil.getProperty(beanTest, "name");
        System.out.println(name);

        BeanTest sourceObj = new BeanTest("李四");
        BeanTest targetObj = new BeanTest();
        BeanUtil.copyProperties(sourceObj, targetObj);
        System.out.println(targetObj.getName());
    }
}
